home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (C) 1989, 1990 Aladdin Enterprises. All rights reserved.
- Distributed by Free Software Foundation, Inc.
-
- This file is part of Ghostscript.
-
- Ghostscript is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY. No author or distributor accepts responsibility
- to anyone for the consequences of using it or for whether it serves any
- particular purpose or works at all, unless he says so in writing. Refer
- to the Ghostscript General Public License for full details.
-
- Everyone is granted permission to copy, modify and redistribute
- Ghostscript, but only under the conditions described in the Ghostscript
- General Public License. A copy of this license is supposed to have been
- given to you along with Ghostscript so you can know your rights and
- responsibilities. It should be in a file named COPYING. Among other
- things, the copyright notice and this notice must be preserved on all
- copies. */
-
- /* gdevegab(ios).c */
- /* EGA driver for GhostScript using BIOS dot-writing routine */
-
- /* Define whether to use assembly code */
- #define USE_ASM 1
- #if USE_ASM
- #pragma inline
- #endif
- #include "gdevega.h"
- #undef DEVICE_STRUCT_NAME
- #define DEVICE_STRUCT_NAME gs_ega_bios_device
- #undef DEVICE_NAME
- #define DEVICE_NAME "ega_bios"
- #include "gdevpcfb.h"
-
- /* Registers and macros for dot writing */
- private registers dot_in_regs, dot_out_regs;
-
- /* Define the dot writing operation */
- #if USE_ASM
- private int dot_x, dot_y;
- private char dot_color;
- #define dot_write()\
- { asm mov cx,dot_x; asm mov dx,dot_y; asm mov al,dot_color;\
- asm mov ah,0ch; asm mov bh,0;\
- asm int 10h;\
- }
- #else /* !USE_ASM */
- #define dot_x dot_in_regs.x.cx
- #define dot_y dot_in_regs.x.dx
- #define dot_color dot_in_regs.h.al
- #define dot_write() int86(0x10, &dot_in_regs, &dot_out_regs)
- #endif
-
- /* Initialize the EGA for graphics mode */
- int
- ega_open()
- { if ( ega_save_mode < 0 ) ega_save_mode = ega_get_mode();
- ega_set_mode(graphics_video_mode);
- dot_in_regs.h.ah = 0xc; /* function */
- dot_in_regs.h.bh = 0; /* page */
- return 0;
- }
-
- /* Write a dot using the EGA color codes. */
- int
- ega_write_dot(gx_device *dev, int x, int y, gx_color_index color)
- { validate_dot();
- dot_color = color;
- dot_x = x;
- dot_y = y;
- dot_write();
- return 0;
- }
-
- /* Copy a monochrome bitmap. The colors are given explicitly. */
- /* Color = gx_no_color_index means transparent (no effect on the image). */
- int
- ega_copy_mono(gx_device *dev, byte *base, int sourcex, int raster,
- int x, int y, int w, int h, gx_color_index zero, gx_color_index one)
- { byte *line = base + (sourcex >> 3);
- int ibit;
- validate_rect();
- ibit = 0x80 >> (sourcex & 7);
- dot_y = y;
- while ( --h >= 0 )
- { byte *bptr = line;
- int count = w;
- int bit = ibit;
- dot_x = x;
- while ( --count >= 0 )
- { gx_color_index color = (*bptr & bit ? one : zero);
- if ( color != gx_no_color_index )
- { dot_color = color;
- dot_write();
- }
- dot_x++;
- if ( !(bit >>= 1) ) bit = 0x80, bptr++;
- }
- dot_y++;
- line += raster;
- }
- return 0;
- }
-
- /* Copy a color pixelmap. This is just like a bitmap, */
- /* except that each pixel takes 4 bits instead of 1. */
- int
- ega_copy_color(gx_device *dev, byte *base, int sourcex, int raster,
- int x, int y, int w, int h)
- { byte *line = base + (sourcex >> 1);
- int ibit;
- validate_rect();
- ibit = (sourcex & 1 ? 0 : -1);
- dot_y = y;
- while ( --h >= 0 )
- { byte *bptr = line;
- int bit = ibit;
- int count = w;
- dot_x = x;
- while ( --count >= 0 )
- { dot_color = ((bit = ~bit) ? *bptr++ & 0xf : *bptr >> 4);
- dot_write();
- dot_x++;
- }
- line += raster;
- dot_y++;
- }
- return 0;
- }
-
- /* Fill a rectangle. */
- int
- ega_fill_rectangle(gx_device *dev, int x, int y, int w, int h,
- gx_color_index color)
- { validate_rect();
- dot_y = y;
- dot_color = color;
- while ( --h >= 0 )
- { dot_x = x;
- { int c = w;
- while ( c-- )
- { dot_write();
- dot_x++;
- }
- }
- dot_y++;
- }
- return 0;
- }
-
- /* Tile a rectangle. */
- int
- ega_tile_rectangle(gx_device *dev, gx_bitmap *tile,
- int x, int y, int w, int h, gx_color_index zero, gx_color_index one)
- { /* We can't do it any faster than the default procedure. */
- return gx_default_tile_rectangle(dev, tile, x, y, w, h, zero, one);
- }
-